import { CustomStyle } from "../constant/CustomStyle";

/**
 * @author duke
 * @description 配置类
 */
export class ElfRefreshConfigurator {
  hasRefresh: boolean = true; // 是否具有下拉刷新功能
  hasLoadMore: boolean = true; // 是否具有上拉加载功能
  hasTwoHeader: boolean = false; // 是否具有两楼
  maxTranslate: number = 160; // 可下拉上拉的最大距离
  closeTwoOffset: number | string = '80%'; // 两楼关闭的偏移量
  sensitivity: number = 0.7; // 下拉上拉灵敏度
  animDuration: number = 150; // 滑动结束后，回弹动画执行时间
  refreshHeight: number = 80; // 下拉动画高度
  loadHeight: number = 80; // 上拉动画高度
  twoLevelHeight: string | number = '100%'; //二楼高度
  refreshAnimDuration: number = 1000; // 自动下拉动画执行一次的时间
  refreshCompleteTextHoldTime: number = 1000; //下拉刷新完毕后, 刷新成功文本停留的时间
  headerStyle: CustomStyle = CustomStyle.Translate // 头部样式
  footerStyle: CustomStyle = CustomStyle.Translate // 尾部样式
  hasAutoLoadMore:boolean = false // 是否自动加载更多

  public setCloseTwoOffset(value: number | string) {
    this.closeTwoOffset = value;
    return this
  }

  public getCloseTwoOffset(): number | string {
    return this.closeTwoOffset;
  }

  public setTwoLevelHeight(value: string | number) {
    this.twoLevelHeight = value;
    return this
  }

  public getTwoLevelHeight(): string | number {
    return this.twoLevelHeight;
  }

  setHasTwoHeader(hasTwoHeader: boolean) {
    this.hasTwoHeader = hasTwoHeader;
    return this;
  }

  getHasTwoHeader() {
    return this.hasTwoHeader;
  }

  setHeaderStyle(headerStyle: CustomStyle) {
    this.headerStyle = headerStyle;
    return this;
  }

  getHeaderStyle() {
    return this.headerStyle;
  }

  setFooterStyle(footerStyle: CustomStyle) {
    this.footerStyle = footerStyle;
    return this;
  }

  getFooterStyle() {
    return this.footerStyle;
  }

  setHasRefresh(hasRefresh: boolean) {
    this.hasRefresh = hasRefresh;
    return this;
  }

  getHasRefresh() {
    return this.hasRefresh;
  }

  setHasLoadMore(hasLoadMore: boolean) {
    this.hasLoadMore = hasLoadMore;
    return this;
  }

  getHasLoadMore() {
    return this.hasLoadMore;
  }

  setMaxTranslate(maxTranslate: number) {
    this.maxTranslate = maxTranslate;
    return this;
  }

  getMaxTranslate() {
    return this.maxTranslate;
  }

  setSensitivity(sensitivity: number) {
    this.sensitivity = sensitivity;
    return this;
  }

  getSensitivity() {
    return this.sensitivity;
  }

  setRefreshHeight(refreshHeight: number) {
    this.refreshHeight = refreshHeight;
    return this;
  }

  getRefreshHeight(): number {
    return this.refreshHeight;
  }

  setLoadHeight(loadHeight: number) {
    this.loadHeight = loadHeight;
    return this;
  }

  getLoadHeight(): number {
    return this.loadHeight;
  }


  setAnimDuration(animDuration: number) {
    this.animDuration = animDuration;
    return this;
  }

  getAnimDuration() {
    return this.animDuration;
  }

  setRefreshCompleteTextHoldTime(refreshCompleteTextHoldTime: number) {
    this.refreshCompleteTextHoldTime = refreshCompleteTextHoldTime;
    return this;
  }

  getRefreshCompleteTextHoldTime(): number {
    return this.refreshCompleteTextHoldTime;
  }


  setRefreshAnimDuration(refreshAnimDuration: number) {
    this.refreshAnimDuration = refreshAnimDuration;
    return this;
  }

  getRefreshAnimDuration() {
    return this.refreshAnimDuration;
  }

  setHasAutoLoadMore(hasAutoLoadMore: boolean) {
    this.hasAutoLoadMore = hasAutoLoadMore;
    return this;
  }

  getHasAutoLoadMore() {
    return this.hasAutoLoadMore;
  }

  /**
   * 创建新配置对象，合并当前配置与传入参数
   * @param params 需要覆盖的配置项（部分属性）
   * @returns 新配置实例
   */
  copyWith(params: Partial<ElfRefreshConfigurator>): ElfRefreshConfigurator {
    const newConfig = new ElfRefreshConfigurator()
    // 复制当前对象属性
    Object.assign(newConfig, this)
    // 覆盖指定属性
    Object.assign(newConfig, params)
    return newConfig
  }
}